package com.sunfeng.netty.atguigu.code;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * @Author : 孙峰
 * @Description:
 * @Date : 2021/10/19  16:30
 */
public class TestUserInfo {
    public static void main(String[] args) throws IOException {
        UserInfo userInfo = new UserInfo();
        userInfo.builderUserID(100)
                .builderUserName("Welcome to Netty");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(userInfo);
        oos.flush();
        oos.close();
        byte[] bytes = bos.toByteArray();

        System.out.println("JDK的序列化方式 长度为"+bytes.length);
        bos.close();

        byte[] bytes1 = userInfo.codeC();

        System.out.println("二进制序列化方式产生的数据长度为"+bytes1.length);

    }
}
